<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #result{
            width: 400px;
            height: 300px;
            border:solid 1px #ddd;
        }
    </style>
</head>
<body>
    <a href="#/">首页</a>
    <a href="#/about">关于我们</a>
    <hr>
    <div id="result">

    </div>

    <script>    
    let result = document.querySelector("#result");

    // 当 url 的 hash 值发生变化的时候, 会触发这个事件
    window.addEventListener('hashchange', function(){
        //获取当前网页的 hash 值
        // console.log(location);
        let {hash} = location;
        switch (hash) {
            case '#/':
                result.innerHTML = '首页内容';
                break;
            case '#/about':
                result.innerHTML = '关于我们';
                break;
            default:
                result.innerHTML = '默认页面';
                break;
        }
    })

    </script>
</body>
</html>